﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeGenerator.Utils
{
    public class FileUtil
    {
        public static void DeleteDirectory(string path)
        {
            if (!Directory.Exists(path))
            {
                return;
            }

            Directory.Delete(path, true);
        }

        public static void CopyDirectoryFiles(string source, string target)
        {
            source = CommonUtil.GenFullPath(source);
            target = CommonUtil.GenFullPath(target);
            // 创建目标文件夹（如果它不存在）
            Directory.CreateDirectory(target);

            // 获取源文件夹中的所有文件和子文件夹
            string[] files = Directory.GetFiles(source, "*", SearchOption.AllDirectories);

            // 复制所有文件和文件夹到目标文件夹
            foreach (string file in files)
            {
                string relativePath = file.Substring(source.Length + 1);
                ;
                string destinationPath = Path.Combine(target, relativePath);

                // 确保目标文件夹存在
                Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
                // 复制文件
                File.Copy(file, destinationPath, true);
            }
        }
    }
}
